--后期埋点统一存放处

TATrackCollect = {}
local mgr = TATrackCollect



--上报背包所有道具
mgr.Track_Bags = function()
    -- local its = logicMgr.ItemManager.getAllItems()

    -- local dict = {}
    -- local tb = {}
    -- for k,v in pairs(its) do
    --     if v.num > 0 then
    --         TAManager.UserSet("item_" .. v.itemModelId, v.num)
    --     end
    -- end
end

--战力前12名英雄
mgr.Track_topHerosTwelve = function()
    local mheros = logicMgr.HeroManager.getOwnerHeroList(nil,nil,true)

    table.sort(mheros, function(a, b)
        if a.power ~= b.power then
            return a.power > b.power
        end
        return tonumber(a.partnerModelId) > tonumber(b.partnerModelId)
    end)

    local dict = {}

    local tb = nil
    local equiplist = nil
    local weaponConfig
    for k,v in pairs(mheros) do
        if k > 6 then
            break
        end
        tb = {}
        tb.hero_name = v.name
        tb.hero_level = v.level
        tb.hero_rank_up_level = v.star
        tb.power = v.power
        tb.weapon_level,tb.weapon_rank = logicMgr.EquipManager.getWeaponLevelByModelId(v.partnerModelId)

        -- 魂石
        local debrisData = logicMgr.StrangeFragmentManager.GetFragmentInfoByPartnerId(v.partnerId)
        if debrisData then
            tb.debris_level = debrisData.level
            tb.debris_id    = debrisData.itemId
            local subskills = debrisData.subSkills
            if subskills and #subskills > 0 then
                local idArr, valueArr = {}, {}
                for i, v in ipairs(subskills) do
                    table.insert(idArr, v.skillId)
                    table.insert(valueArr, v.val)
                end
                tb.sub_skill_ids  = table.concat(idArr, "_")
                tb.sub_skill_vals = table.concat(valueArr, "_")
            end
        end

        -- equiplist = logicMgr.EquipManager.getHeroEquipList(v.partnerId, true)
        -- for kk,vv in pairs(equiplist) do
        --     tb["equip_" .. vv.itemModelId] = {}
        --     tb["equip_" .. vv.itemModelId].curRfLevel = vv.curRfLevel
        --     tb["equip_" .. vv.itemModelId].quality = vv.quality
        -- end
        dict["hero_" .. v.partnerModelId] = tb

    end
    local str = getJsonStr(dict)
    TAManager.UserSet("Top_Hero_Twelve", str)
end

mgr.Track_Pet = function()
    TAManager.UserSet("pet_level", logicMgr.PetManager.petLv)
    TAManager.UserSet("elves_level", logicMgr.PetManager.EvoLevel)
end

mgr.Track_Fetter = function()
    local acount = logicMgr.HeroManager.GetHeroFetterAwardValue()

    local id = 0
    local ls = G.dataTable["t_trammelpointreward"]
    
    local count = table.getn(ls)
    for i=1, count do
        if ls[tostring(i)] and ls[tostring(i)].f_Point < acount then
            id = i
        else
            break
        end
    end
    
    TAManager.UserSet("current_reborn_num", id)
end

mgr.Track_Other = function()
    --当前永劫之境层数
    TAManager.UserSet("current_mythic_rank", logicMgr.MythicDungeonsManager.getLayer()) 
    --竞技场
    local info = logicMgr.ArenaManager.getRankInfo()
    if info and info.myRank then
        TAManager.UserSet("current_arena_rank", info.myRank.rank)
    else
        TAManager.UserSet("current_arena_rank", 0)
    end
end

mgr.Track_AllPower = function()
    local powerstr = logicMgr.HeroManager.GetHerosSumPower()
    TAManager.UserSet("role_power", powerstr)
end

mgr.Track_ClimbTower = function()
    local info = logicMgr.TowerManager.returnTowerInfo(1)
    if info then
        TAManager.UserSet("current_tower_rank", info.layerId)
    end
end

--支援技
mgr.Track_SupSkill = function()
    local supSkills = logicMgr.SkillManager.getSupSkillInfo()
    local supSkillId = 0
    for i = 1, #supSkills do
        if supSkills[i].isUse == 1 then
            supSkillId = tostring(supSkills[i].skillId)
            local skillData = G.dataTable["t_skillshow"][tostring(supSkillId)]
            TAManager.UserSet("AssistantSkill_name", skillData.f_SkillName)
            TAManager.UserSet("AssistantSkill_level", supSkills[i].skillLev)
            break
        end
    end
    
    -- if supSkillId == 0 and #supSkills > 0 then
    --     TAManager.UserSet("AssistantSkill_level", supSkills[1].skillLev)
    --     TAManager.UserSet("AssistantSkill_name", "")
    -- end
end

--暴风峡湾
mgr.Track_Chaos = function()
    local msg = logicMgr.TrialsManager.GetTrialsInfo();
    if msg and msg.maxLevel then
        TAManager.UserSet("current_trials_rank", msg.maxLevel)
    end
end

--远征
mgr.Track_Expedition = function()
    if logicMgr.ExpeditionMgr.mapId ~= 0 then
        TAManager.UserSet("current_expedition_rank", table.concat({logicMgr.ExpeditionMgr.mapId, "_", logicMgr.ExpeditionMgr.currentStageId}))
    end
end

mgr.OnApplicationQuit = function()
    mgr.Track_topHerosTwelve()
    mgr.Track_Pet()
    mgr.Track_Fetter()
    mgr.Track_Other()
    mgr.Track_ClimbTower()
    mgr.Track_SupSkill()
    mgr.Track_Chaos()
    mgr.Track_Expedition()
end

return TATrackCollect